Quality control and filtering results from cellranger

Sample info and environment setup

PRJNA723584

setwd("/media/jacopo/Elements/re_align/MM/PRJNA723584/SAMN18822748/SRR14295363/")
# Load the libraries (from Sarah script + biomart)
library(tidyverse) # packages for data wrangling, visualization etc
library(Seurat) # scRNA-Seq analysis package
library(clustree) # plot of clustering tree 
library(ggsignif) # Enrich your 'ggplots' with group-wise comparisons
library(clusterProfiler) #The package implements methods to analyze and visualize functional profiles of gene and gene clusters.
library(org.Hs.eg.db) # Human annotation package neede for clusterProfiler
library(ggrepel) # extra geoms for ggplo2
library(patchwork) #multiplots
library(reticulate)

Load and process cellranger data

Load and do the QC for the cellranger data

#list.files(".")
dat <- Read10X(data.dir ="./out/counts_filtered/")
dat <- CreateSeuratObject(dat) # Create the seurat object from the 10x data
kb.initial <- dat@assays[["RNA"]]@counts@Dim[[2]]
cat("Initial number of cells:", kb.initial, 
    "\nNumber of genes:",  dat@assays[["RNA"]]@counts@Dim[[1]])
## Initial number of cells: 13421 
## Number of genes: 36601

Quality Control

Empty cells were already filtered, check for % mt RNA and death markers:

# first calculate the mitochondrial percentage for each cell
dat$percent_mt <- PercentageFeatureSet(dat, pattern="^MT.")
# make violin plots
mt_rna = 10
max_counts = 25000



# Check some feature-feature relationships
# % mt RNA vs n Counts, n Features vs n Counts
# Check some feature-feature relationships
# % mt RNA vs n Counts, n Features vs n Counts
VlnPlot(dat, features = c("nCount_RNA", "nFeature_RNA", "percent_mt"))  + geom_hline(yintercept=mt_rna, linetype = "dotted")

plot1 <- FeatureScatter(dat, feature1 = "nCount_RNA", feature2 = "percent_mt")
plot1 <- plot1 + geom_hline(yintercept=mt_rna, linetype = "dotted")
plot2 <- FeatureScatter(dat, feature1 = "nCount_RNA", feature2 = "nFeature_RNA")
plot2 <- plot2 + geom_vline(xintercept = max_counts, linetype = "dotted")
plot1 

plot2

##  cells retained by mt RNA content ( 10 %): 4375 
##  percentage of retained cells: 32.6 %
## cells retained by counts ( 25000 ): 4350 
##  percentage of retained cells: 32.41 %

Check the distribution of the cells with low counts and control death markers:

min_counts = 300


hist(dat@meta.data$nCount_RNA, breaks = 100, xlab = "Counts")

hist(dat@meta.data$nCount_RNA, breaks = 1000, xlab = "Counts", xlim = c(0,5000))

hist(dat@meta.data$nCount_RNA, breaks = 10000, xlab = "Counts", xlim = c(0,1000))
abline(v=min_counts, col="red", lty = 3)

The evident peak of cells with < 200 counts could contain dying cells.

# Subset the dataset to focus only on those cells with low counts
dat.lowcount <- subset(dat, subset = nCount_RNA < min_counts)

# Get the mean of the counts for each gene and sort them decreasing
meanCounts <- rowMeans(GetAssayData(object = dat.lowcount, slot = 'counts'))
meanCounts <- sort(meanCounts, decreasing = T)

# A boxplot can help to observe the distribution of the means
#boxplot(meanCounts)

# Print the most highly expressed genes
head(meanCounts, 30)
##       IGKC     MALAT1      IGHG1      RPLP1     MT-CO2      IGHG3     RPL18A 
## 24.7896774  3.6361290  1.5883871  1.4580645  1.1122581  1.0296774  0.6748387 
##        B2M     MT-CO1     MT-CO3     JCHAIN    MT-ATP6      RPS15      RPS28 
##  0.6632258  0.6503226  0.6400000  0.6348387  0.6283871  0.6025806  0.5729032 
##     MT-ND4      RPL32      RPL13     EEF1A1      RPS18        FTL      RPL29 
##  0.5651613  0.5548387  0.5509677  0.5109677  0.4929032  0.4838710  0.4787097 
##      RPL41      RPL10     MT-CYB      RPS12      RPL37      RPL28      UBA52 
##  0.4606452  0.4477419  0.4425806  0.4232258  0.4167742  0.4077419  0.4051613 
##       TPT1      RPS14 
##  0.3987097  0.3935484
## cells retained by counts ( 300 ): 3575 
##  percentage of retained cells: 26.64 %

dir.create("result")
saveRDS(dat, file = "./result/SAMN18822748_clean_QC.Rds")

Feature selection

#Normalize
dat <- NormalizeData(dat)
# Find the first 4000 variabe features
dat <- FindVariableFeatures(dat, selection.method = "vst", nfeatures = 4000)

Data scaling

Set mean expression to 0 and variance across 1 to avoid highly expressed genes drive the forwarding analyses. Since negative expression is meaningless, scaled data are useful only for UMAP and clustering

# scale data, the scaled data are saved in:
# dat[["RNA"]]@scale.data

all.genes <- rownames(dat)

dat <- ScaleData(dat, vars.to.regress = c("percent_mt","nCount_RNA"))

Dimensionality reduction

dat <- RunPCA(dat, features = VariableFeatures(object = dat), verbose = F, seed.use = 1)
print(dat[["pca"]], dims = 1:5, nfeatures = 5)
## PC_ 1 
## Positive:  STMN1, HMGB2, TUBA1B, NUSAP1, MKI67 
## Negative:  DNAJB9, IGHG1, TNFRSF17, MT-CO2, ISG20 
## PC_ 2 
## Positive:  DUT, FAM111B, HELLS, PCNA, GINS2 
## Negative:  CCNB1, PLK1, CCNB2, ARL6IP1, NEK2 
## PC_ 3 
## Positive:  RRM2, HIST1H4C, PCLAF, STMN1, NUSAP1 
## Negative:  RPL18A, RPS24, HSP90AB1, NCL, RPS2 
## PC_ 4 
## Positive:  RPL7A, IGHG1, RPS18, MIF, RPS23 
## Negative:  MALAT1, XAF1, NEAT1, TXNIP, MX1 
## PC_ 5 
## Positive:  JCHAIN, HERPUD1, MTDH, DNAAF1, CACYBP 
## Negative:  TMSB10, B2M, RPL18A, RPS15, LY6E

UMAP

UMAP is a graph-based method of clustering. The first step in this process is to construct a KNN graph based on the euclidean distance in PCA space:

dat <- FindNeighbors(dat, dims = 1:20)

The graph now can be used as input for the function runUMAP()

dat <- RunUMAP(dat, dims = 1:20, seed.use = 1)
DimPlot(dat, reduction = 'umap', seed = 1)

Final plots:

## QC metrics

## markers